package com.ruihu.admin.module.business.tasknode.domain.entity;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.annotation.TableName;
import com.ruihu.admin.common.domain.BaseEntity;
import com.ruihu.admin.module.business.tasknode.domain.dto.NodeInstProcessRelationAddDTO;
import com.ruihu.admin.module.business.tasknode.domain.dto.NodeInstProcessRelationDTO;
import com.ruihu.admin.module.business.tasknode.domain.dto.NodeInstProcessRelationUpdateDTO;
import lombok.Data;

import java.util.Objects;

/**
 * [  ]
 *
 * @author Tony
 * @version 1.0
 * @company 瑞虎（南京）信息技术有限公司
 * @copyright (c)  瑞虎（南京）信息技术有限公司Inc. All rights reserved.
 * @date 2023-01-03 14:55:43
 * @since JDK1.8
 */

@Data
@TableName("t_node_inst_process_relation")
public class NodeInstProcessRelationEntity extends BaseEntity {


    /**
     * 流程配置表ID
     */
    private Long processConfigId;

    /**
     * 任务环节实例ID
     */
    private Long taskNodeInstId;

    /**
     * 子任务环节实例ID
     */
    private Long subTaskNodeInstId;

    /**
     * 固定值
     */
    private String configValue;

    /**
     * 选择值
     */
    private String selectValue;

    /**
     * 描述
     */
    private String descr;


    /**
     * 其他值
     */
    private String otherValue;



    public static NodeInstProcessRelationEntity convertToNodeInstProcessRelationEntity(NodeInstProcessRelationAddDTO addDTO) {
        if (addDTO == null) {
            return null;
        }

        NodeInstProcessRelationEntity entity = new NodeInstProcessRelationEntity();
        entity.setProcessConfigId(addDTO.getProcessConfigId());
        entity.setTaskNodeInstId(addDTO.getTaskNodeInstId());
        entity.setConfigValue(addDTO.getConfigValue());
        entity.setSelectValue(addDTO.getSelectValue());
        entity.setDescr(addDTO.getDescr());
        entity.setOtherValue(addDTO.getOtherValue());
        return entity;
    }


    public static NodeInstProcessRelationEntity convertToNodeInstProcessRelationEntity(NodeInstProcessRelationUpdateDTO updateDTO) {
        if (updateDTO == null) {
           return null;
        }

        NodeInstProcessRelationEntity entity = new NodeInstProcessRelationEntity();
        entity.setId(updateDTO.getId());
        entity.setProcessConfigId(updateDTO.getProcessConfigId());
        entity.setTaskNodeInstId(updateDTO.getTaskNodeInstId());
        entity.setConfigValue(updateDTO.getConfigValue());
        entity.setSelectValue(updateDTO.getSelectValue());
        entity.setDescr(updateDTO.getDescr());
        entity.setOtherValue(updateDTO.getOtherValue());
        return entity;
    }

    public static NodeInstProcessRelationEntity convertToNodeInstProcessRelationEntity(NodeInstProcessRelationDTO dto) {
        if (dto == null) {
           return null;
        }

        NodeInstProcessRelationEntity entity = new NodeInstProcessRelationEntity();
        entity.setId(dto.getId());
        entity.setProcessConfigId(dto.getProcessConfigId());
        entity.setTaskNodeInstId(dto.getTaskNodeInstId());
        entity.setSubTaskNodeInstId(dto.getSubTaskNodeInstId());
        entity.setConfigValue(dto.getConfigValue());
        entity.setSelectValue(dto.getSelectValue());
        entity.setDescr(dto.getDescr());
        entity.setOtherValue(dto.getOtherValue());
        entity.setCreateTime(dto.getCreateTime());
        entity.setUpdateTime(dto.getUpdateTime());
        return entity;
    }

    public static NodeInstProcessRelationEntity copyIgnoreNullAndEmpty(NodeInstProcessRelationEntity sourceEntity, NodeInstProcessRelationEntity destEntity) {
        if (Objects.isNull(sourceEntity))
            return destEntity;
        if (Objects.nonNull(sourceEntity.getId())) {
           destEntity.setId(sourceEntity.getId());
        }
        if (Objects.nonNull(sourceEntity.getProcessConfigId())) {
           destEntity.setProcessConfigId(sourceEntity.getProcessConfigId());
        }
        if (Objects.nonNull(sourceEntity.getTaskNodeInstId())) {
           destEntity.setTaskNodeInstId(sourceEntity.getTaskNodeInstId());
        }
        if (Objects.nonNull(sourceEntity.getSubTaskNodeInstId())) {
            destEntity.setSubTaskNodeInstId(sourceEntity.getSubTaskNodeInstId());
        }
        if (StrUtil.isNotEmpty(sourceEntity.getConfigValue())) {
           destEntity.setConfigValue(sourceEntity.getConfigValue());
        }
        if (StrUtil.isNotEmpty(sourceEntity.getSelectValue())) {
           destEntity.setSelectValue(sourceEntity.getSelectValue());
        }
        if (StrUtil.isNotEmpty(sourceEntity.getDescr())) {
           destEntity.setDescr(sourceEntity.getDescr());
        }
        if (StrUtil.isNotEmpty(sourceEntity.getOtherValue())) {
            destEntity.setOtherValue(sourceEntity.getOtherValue());
        }
        if (Objects.nonNull(sourceEntity.getCreateTime())) {
           destEntity.setCreateTime(sourceEntity.getCreateTime());
        }
        if (Objects.nonNull(sourceEntity.getUpdateTime())) {
           destEntity.setUpdateTime(sourceEntity.getUpdateTime());
        }
        return destEntity;
    }
}
